package controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import service.ClientManager;
import vo.Address;
import vo.Client;
import vo.OrderForm;

@Controller
public class ClientController {
	@Autowired(required=true)
	private ClientManager cm;
	/** 用户登陆 */
	@RequestMapping("/cltLogin")
	public String login(String username,String passwd,HttpServletRequest request){
		Client client = cm.login(username, passwd);
		System.out.println(client+"+++++++++++++++++++");
		if(client!=null){
			request.setAttribute("client", client);
			return "loginSuc";
		}
		else{
			
			return "login";
		}
	}
	
	/** 用户注册 */
	@RequestMapping("cltRegist")
	public String regist(Client client,Address adds,HttpServletRequest request){
		int rs1 = cm.cltAdress(adds);
		int rs2 = cm.regist(client);
		if(rs1>0 && rs2>0 ) 
			return "redirect:/regSuc.jsp";
		else return "regist";
	}
	
	/**用户下单*/
	@RequestMapping("cltConsume")
	public String consume(OrderForm orderform,HttpServletRequest request){
		
		return null;
	}
}
